<!DOCTYPE html>
<html>
<head>
    <title>认证状态调试</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .info { background: #f0f8ff; padding: 10px; margin: 10px 0; border-radius: 5px; }
        .error { background: #ffe6e6; padding: 10px; margin: 10px 0; border-radius: 5px; }
        .success { background: #e6ffe6; padding: 10px; margin: 10px 0; border-radius: 5px; }
        button { padding: 10px 20px; margin: 5px; background: #007bff; color: white; border: none; border-radius: 3px; cursor: pointer; }
        button:hover { background: #0056b3; }
        .clear-btn { background: #dc3545; }
        .clear-btn:hover { background: #c82333; }
    </style>
</head>
<body>
    <h1>Vue Element Admin 认证状态调试</h1>
    
    <div class="info">
        <h3>当前认证状态:</h3>
        <div id="auth-status"></div>
    </div>
    
    <div class="info">
        <h3>Cookie信息:</h3>
        <div id="cookie-info"></div>
    </div>
    
    <div class="info">
        <h3>LocalStorage信息:</h3>
        <div id="localstorage-info"></div>
    </div>
    
    <div>
        <button onclick="checkAuth()">检查认证状态</button>
        <button onclick="clearAllAuth()" class="clear-btn">清除所有认证信息</button>
        <button onclick="goToLogin()">前往登录页</button>
        <button onclick="goToHome()">前往首页</button>
    </div>

    <script>
        function getCookie(name) {
            const value = `; ${document.cookie}`;
            const parts = value.split(`; ${name}=`);
            if (parts.length === 2) return parts.pop().split(';').shift();
            return null;
        }

        function checkAuth() {
            const adminToken = getCookie('Admin-Token');
            const authStatus = document.getElementById('auth-status');
            
            if (adminToken) {
                authStatus.innerHTML = `
                    <div class="error">
                        <strong>发现Token:</strong> ${adminToken}<br>
                        <strong>问题:</strong> 浏览器中存在认证Token，这会阻止跳转到登录页面。
                    </div>
                `;
            } else {
                authStatus.innerHTML = `
                    <div class="success">
                        <strong>状态正常:</strong> 没有发现Admin-Token，应该会跳转到登录页面。
                    </div>
                `;
            }
            
            // 显示所有cookie
            const cookieInfo = document.getElementById('cookie-info');
            const allCookies = document.cookie;
            cookieInfo.innerHTML = allCookies ? 
                `<pre>${allCookies}</pre>` : 
                '<em>没有找到任何Cookie</em>';
            
            // 显示localStorage
            const localStorageInfo = document.getElementById('localstorage-info');
            const localStorageContent = {};
            for (let i = 0; i < localStorage.length; i++) {
                const key = localStorage.key(i);
                localStorageContent[key] = localStorage.getItem(key);
            }
            localStorageInfo.innerHTML = Object.keys(localStorageContent).length > 0 ?
                `<pre>${JSON.stringify(localStorageContent, null, 2)}</pre>` :
                '<em>没有找到任何LocalStorage数据</em>';
        }

        function clearAllAuth() {
            // 清除所有cookies
            document.cookie.split(";").forEach(function(c) { 
                document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); 
            });
            
            // 特别清除Admin-Token
            document.cookie = "Admin-Token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
            
            // 清除localStorage
            localStorage.clear();
            
            // 清除sessionStorage
            sessionStorage.clear();
            
            alert('所有认证信息已清除！');
            checkAuth();
        }

        function goToLogin() {
            window.location.href = 'http://localhost:9529/login';
        }

        function goToHome() {
            window.location.href = 'http://localhost:9529/';
        }

        // 页面加载时自动检查
        window.onload = function() {
            checkAuth();
        };
    </script>
</body>
</html>